package com.zzz.framework.model;

import lombok.Data;
import lombok.experimental.Accessors;

import java.util.List;

@Accessors(chain = true)
@Data
public class R<T> {
    private int status;
    private String msg;
    private T data;

    public static <T> R<T> data(T data) {
        R<T> r = new R();
        r.data = data;
        return r;
    }

    public static <T> R<PageResult<T>> page(long total, List<T> rows) {
        return data(new PageResult((int) total, rows));
    }

    public static <T> R<T> error(String msg) {
        return error(-1, msg);
    }

    public static <T> R<T> error(int status, String msg) {
        R<T> r = new R();
        r.msg = msg;
        r.status = status;
        return r;
    }
}
